﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RacePlatformer;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using Dwarfs.Manager;

namespace Dwarfs.Screens
{
    public class PauseScreen : Screen
    {
        private Color continueColor = Color.White,
            loadGameColor = Color.White,
            optionColor = Color.White,
            ExitToMMColor = Color.White;
        private enum selectedIndex
        {
            Continue,
            LoadGame,
            Options,
            ExitTOMM
        };
        private selectedIndex currentSelectedIndex = 0;
        public PauseScreen(MainGame maingame)
            : base(maingame)
        {

        }
        public override void UpdateMenu()
        {
            KeyboardState currentKeyboardState = Keyboard.GetState();
            maingame.soundmanager.playBackgroundSound(this);
            if (previousKeyboardState.IsKeyDown(Keys.Escape) && currentKeyboardState.IsKeyUp(Keys.Escape))
            {
                SoundManager.stopBackgroundSound();
                maingame.currentGameState = MainGame.GameState.INGAME;
            }
            if (previousKeyboardState.IsKeyDown(Keys.Enter) && currentKeyboardState.IsKeyUp(Keys.Enter))
            {
                switch (currentSelectedIndex)
                {
                    case selectedIndex.Continue:
                        SoundManager.stopBackgroundSound();
                        maingame.currentGameState = MainGame.GameState.INGAME;
                        break;
                }
            }
            if (previousKeyboardState.IsKeyDown(Keys.Down) && currentKeyboardState.IsKeyUp(Keys.Down))
            {
                if (currentSelectedIndex != selectedIndex.ExitTOMM)
                {
                    currentSelectedIndex++;
                }
                else
                {
                    currentSelectedIndex = 0;
                }
            }

            if (previousKeyboardState.IsKeyDown(Keys.Up) && currentKeyboardState.IsKeyUp(Keys.Up))
            {
                if (currentSelectedIndex != selectedIndex.Continue)
                {
                    currentSelectedIndex--;
                }
                else
                {
                    currentSelectedIndex = selectedIndex.ExitTOMM;
                }
            }
            previousKeyboardState = currentKeyboardState;
        }
        public override void DrawScreen(Microsoft.Xna.Framework.GameTime gameTime, SpriteBatch batch)
        {
            batch.Draw(screenBackground, new Rectangle(0, 0, MainGame.SCREEN_WIDTH, MainGame.SCREEN_HEIGHT), Color.White);
            switch (currentSelectedIndex)
            {
                case selectedIndex.Continue:
                    continueColor = Color.Yellow;
                    break;
                case selectedIndex.LoadGame:
                    loadGameColor = Color.Yellow;
                    break;
                case selectedIndex.Options:
                    optionColor = Color.Yellow;
                    break;
                case selectedIndex.ExitTOMM:
                    ExitToMMColor = Color.Yellow;
                    break;
            }
            batch.DrawString(screenFont, "Continue", new Vector2((MainGame.SCREEN_WIDTH / 2) - selectedIndex.Continue.ToString().Length, (MainGame.SCREEN_HEIGHT / 2) - 50), continueColor);
            batch.DrawString(screenFont, "Load Game", new Vector2((MainGame.SCREEN_WIDTH / 2) - selectedIndex.LoadGame.ToString().Length, (MainGame.SCREEN_HEIGHT / 2)), loadGameColor);
            batch.DrawString(screenFont, "Options", new Vector2((MainGame.SCREEN_WIDTH / 2) - selectedIndex.Options.ToString().Length, (MainGame.SCREEN_HEIGHT / 2) + 50), optionColor);
            batch.DrawString(screenFont, "Exit to Main Menu", new Vector2((MainGame.SCREEN_WIDTH / 2) - selectedIndex.ExitTOMM.ToString().Length, (MainGame.SCREEN_HEIGHT / 2) + 100), ExitToMMColor);
            resetColors();
        }
        public void resetColors()
        {
            continueColor = Color.White;
            loadGameColor = Color.White;
            optionColor = Color.White;
            ExitToMMColor = Color.White;
        }
        public override void LoadContent()
        {
            screenBackground = maingame.Content.Load<Texture2D>("screens/menuScreen");
            base.LoadContent();
        }
    }
}
